package admin

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

var (
	WechatController = Wechat{
		Prefix: "/v1", // [可选] 路由前缀
		Method: map[string]interface{}{
			"GetUserName": "get",
			"GetInfo":     []string{"post", "Get"},
		},
		Middleware: []gin.HandlerFunc{
			func(ctx *gin.Context) {
				fmt.Println("前置中间件")
				// 前置中间件
				ctx.Next()
			},
			func(ctx *gin.Context) {
				ctx.Next() // 后置中间件
				fmt.Println("后置中间件")
			},
		},
	}
)

type Wechat struct {
	// 地址: ["/api"(前缀) + ] "/包名/结构体名称/方法"
	// 路由前缀
	Prefix string `json:"prefix,omitempty"`
	// 方法请求方式: [POST/GET等等]
	Method map[string]interface{} `json:"method,omitempty"`
	// 中间件
	Middleware []gin.HandlerFunc `json:"middleware,omitempty"`
	// 后置中间件
	AfterMiddleware []gin.HandlerFunc `json:"after_middleware,omitempty"`
}

// Login [post请求]admin/wechat/login
func (w *Wechat) Login(ctx *gin.Context) {
	fmt.Println("正在登录中......")
	ctx.Writer.Write([]byte("4555"))
}

// Register [POST]admin/wechat/register
func (w *Wechat) Register(ctx *gin.Context) {
	ctx.Writer.Write([]byte("RegisterByPost"))
}

// GetInfo [Any] admin/wechat/get_info
func (w *Wechat) GetInfo(ctx *gin.Context) {
	ctx.Writer.Write([]byte("GetInfo"))
}

// GetUserName [GET] admin/wechat/get_user_name
func (w *Wechat) GetUserName(ctx *gin.Context) {
	ctx.Writer.Write([]byte("GetUserName"))
}

// GetUserLists [GET] admin/wechat/get_user_name
func (w *Wechat) GetUserLists(ctx *gin.Context) (err error) {
	ctx.Writer.Write([]byte("GetUserLists"))
	return nil
}

func (w Wechat) TestName() {

}
